<?php

class m130727_170525_AddSomeNewTable extends CDbMigration
{
	public function up()
	{
		$this->execute("
			CREATE TABLE `amenities` (
			  `id` bigint(20) NOT NULL AUTO_INCREMENT,
			  `title` varchar(255) NOT NULL,
			  `status` tinyint(1) NOT NULL DEFAULT '1',
			  PRIMARY KEY (`id`)
			);

			CREATE TABLE `estate` (
			  `id` bigint(20) NOT NULL AUTO_INCREMENT,
			  `estate_id` int(11) NOT NULL,
			  `title` varchar(255) NOT NULL,
			  `address` text NOT NULL,
			  `location_id` bigint(20) NOT NULL COMMENT 'district',
			  `feature_id` bigint(20) DEFAULT NULL,
			  `price` float NOT NULL,
			  `bedrooms` tinyint(2) DEFAULT NULL,
			  `bathrooms` tinyint(2) DEFAULT NULL,
			  `keyword` text,
			  `parking_space` int(11) DEFAULT NULL,
			  `description` text NOT NULL,
			  `year_built` date DEFAULT NULL,
			  `sale_rent_type` tinyint(1) NOT NULL DEFAULT '1' COMMENT '1: for sale, 2: for rent',
			  `you_are_the_id` bigint(20) NOT NULL,
			  `property_is_for_id` bigint(20) NOT NULL,
			  `type_of_property_id` bigint(20) NOT NULL,
			  `in_condominuim_id` bigint(20) NOT NULL,
			  `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '1: active, 0: inactive',
			  `created_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
			  `is_vip` tinyint(1) NOT NULL DEFAULT '0' COMMENT '1: vip, 0: none',
			  PRIMARY KEY (`id`)
			);
			
			CREATE TABLE `estate_amenities` (
				`id` bigint(20) NOT NULL AUTO_INCREMENT,
				`estate_id` bigint(20) NOT NULL,
				`amenities_id` bigint(20) NOT NULL,
				PRIMARY KEY (`id`)
			);

			CREATE TABLE `estate_image` (
				`id` bigint(20) NOT NULL AUTO_INCREMENT,
				`estate_id` bigint(20) NOT NULL,
				`image_id` bigint(20) NOT NULL,
				PRIMARY KEY (`id`)
			);

			CREATE TABLE `estate_user` (
				`id` bigint(20) NOT NULL AUTO_INCREMENT,
				`estate_id` bigint(20) NOT NULL,
				`user_id` bigint(20) NOT NULL,
				PRIMARY KEY (`id`)
			);

			CREATE TABLE `feature` (
				`id` bigint(20) NOT NULL AUTO_INCREMENT,
				`title` varchar(255) NOT NULL,
				`status` tinyint(1) NOT NULL DEFAULT '1',
				PRIMARY KEY (`id`)
			);

			CREATE TABLE `image` (
				`id` bigint(20) NOT NULL AUTO_INCREMENT,
				`title` varchar(255) NOT NULL,
				`status` tinyint(1) NOT NULL DEFAULT '1',
				PRIMARY KEY (`id`)
			);

			CREATE TABLE `in_condominuim` (
				`id` bigint(20) NOT NULL AUTO_INCREMENT,
				`title` varchar(255) NOT NULL,
				`status` tinyint(1) NOT NULL DEFAULT '1',
				PRIMARY KEY (`id`)
			);

			CREATE TABLE `location` (
				`id` bigint(20) NOT NULL AUTO_INCREMENT,
				`title` varchar(255) NOT NULL,
				`status` tinyint(1) NOT NULL DEFAULT '1',
				PRIMARY KEY (`id`)
			);

			CREATE TABLE `property_is_for` (
				`id` bigint(20) NOT NULL AUTO_INCREMENT,
				`title` varchar(255) NOT NULL,
				`status` tinyint(1) NOT NULL DEFAULT '1',
				PRIMARY KEY (`id`)
			);

			CREATE TABLE `type_of_property` (
				`id` bigint(20) NOT NULL AUTO_INCREMENT,
				`title` varchar(255) NOT NULL,
				`status` tinyint(1) NOT NULL DEFAULT '1',
				PRIMARY KEY (`id`)
			);

			CREATE TABLE `you_are_the` (
				`id` bigint(20) NOT NULL AUTO_INCREMENT,
				`title` varchar(255) NOT NULL,
				`status` tinyint(1) NOT NULL DEFAULT '1',
				PRIMARY KEY (`id`)
			);

		");
	}

	public function down()
	{
		echo "m130727_170525_AddSomeNewTable does not support migration down.\n";
		return false;
	}

	/*
	// Use safeUp/safeDown to do migration with transaction
	public function safeUp()
	{
	}

	public function safeDown()
	{
	}
	*/
}